package com.wantup.miaosha.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wantup.miaosha.entity.TblGoods;
import com.wantup.miaosha.pojo.GoodsPojo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author 赵洛伟
 * @since 2019-06-06
 */
@Mapper
@Repository
public interface TblGoodsMapper extends BaseMapper<TblGoods> {

    //查询 秒杀 商品
    @Select("SELECT g.*,mg.stockCount,mg.miaoShaPrice,\n" +
            "\t\t\t DATE_FORMAT(mg.startDate,'%Y-%m-%d %H:%i:%s')startDate ,\n" +
            "\t\t\t DATE_FORMAT(mg.endDate ,'%Y-%m-%d %H:%i:%s')endDate\n" +
            "FROM tbl_miaosha_goods mg LEFT JOIN tbl_goods g ON mg.goodsId = g.id")
    public List<GoodsPojo> listGoodsVo();

    @Select("SELECT g.*,mg.stockCount,mg.miaoShaPrice,\n" +
            "\t\t\t DATE_FORMAT(mg.startDate,'%Y-%m-%d %H:%i:%s')startDate ,\n" +
            "\t\t\t DATE_FORMAT(mg.endDate ,'%Y-%m-%d %H:%i:%s')endDate\n" +
            "FROM tbl_miaosha_goods mg LEFT JOIN tbl_goods g ON mg.goodsId = g.id WHERE g.id = #{id}")
    GoodsPojo getGoodsInfoByGoodsId(@Param("id") String id) throws Exception;
}
